package _1GongChang.factory;

import _1GongChang.Operation;
import _1GongChang.impl.Add;
import _1GongChang.impl.Div;
import _1GongChang.impl.Mul;
import _1GongChang.impl.Sub;

/**
 * @EasyFactory: 简单工厂类
 * @author: ZBoHang
 * @time: 2021/9/1 15:39
 */
public class EasyFactory {

    private static Operation oper = null;

    public static Operation createOperation(String name) {

        switch (name) {
            case "+":
                oper = add();
                break;
            case "-":
                oper = sub();
                break;
            case "*":
                oper = mul();
                break;
            case "/":
                oper = div();
                break;
            default:
                return null;
        }
        return oper;
    }

    private static Operation div() {
        return new Div();
    }

    private static Operation mul() {
        return new Mul();
    }

    private static Operation sub() {
        return new Sub();
    }

    private static Operation add() {
        return new Add();
    }
}
